home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Utilities / PGP / source / pgp50i-b8a / tools / subst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-04  |  4.3 KB  |  110 lines

  1. /*
  2.  * subst.c -- Repair substitution tables
  3.  *
  4.  * Copyright (C) 1997 Pretty Good Privacy, Inc.
  5.  *
  6.  * Written by Colin Plumb
  7.  *
  8.  * $Id: subst.c,v 1.2 1997/07/09 15:07:50 colin Exp $
  9.  *
  10.  * IT IS EXPECTED that users of this program will play with these tables
  11.  * and the cost values in the subst.h header.  (Some day, they'll all
  12.  * get moved to an external config file.)
  13.  *
  14.  * NOTE: Other cost are hiding in the TabFilter function.
  15.  * Remember to keep them all on the same scale.
  16.  */
  17.  
  18. /*
  19.  * The repair program copies its input to its output, making various
  20.  * substitutions, until it manages to produce a version that satisfies
  21.  * the parser.  This includes having a correct CRC for each line.
  22.  * Each substitution has a cost, and the combinations are tried in order
  23.  * of increasing cost.  NOTE that even translating "A"->"A" counts as
  24.  * a substitution, although it may have zero cost.
  25.  *
  26.  * The intention is to correct transcription errors, where the
  27.  * errors have a distinctly non-uniform distribution.  Slight
  28.  * differences in cost produce a preference in trying some errors
  29.  * first.  If an error costs half as much as another, combinations
  30.  * of two of that error will be compared to one of the more expensive.
  31.  * Too many cheap substitutions will result is repair spending
  32.  * a very log time searching before considering the more expensive
  33.  * substitutions.
  34.  *
  35.  * The following parameters and the raw substitution tables are expected
  36.  * to be edited by the user based on experience.  Eventually, this
  37.  * will be moved into an external config file, but for now it's a matter
  38.  * of recompiling.
  39.  */
  40.  
  41. #include "subst.h"
  42. #include "util.h"
  43.  
  44. /*
  45.  * The input substitutions to make (one-to-one).   These are listed in
  46.  * the order of correction. i.e. uncorrected input first, then corrected
  47.  * output.  Substitutions are one-way; to get two-way, list it twice.
  48.  */
  49.  
  50. struct RawSubst const substSingles[] = {
  51.     { " !\"#$%&'()*+,-./0123456789:;<=>?",
  52.       " !\"#$%&'()*+,-./0123456789:;<=>?", 0, NULL },
  53.     { "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
  54.       "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", 0, NULL },
  55.     { "`abcdefghijklmnopqrstuvwxyz{|}~\f" TAB_STRING FORMFEED_STRING,
  56.       "`abcdefghijklmnopqrstuvwxyz{|}~\f" TAB_STRING FORMFEED_STRING, 0, NULL },
  57. #if (TAB_PAD_CHAR & 128)    /* Not already included? */
  58.     { TAB_PAD_STRING, TAB_PAD_STRING, COST_LINE, NULL },
  59. #endif
  60.     { "\n", "\n", COST_LINE, NULL },
  61.     /* Common substitutions.  These costs should be fiddled */
  62.     { "-", "_", 1, NULL },    /* A *very* common error */
  63.     { "()[]", "[]{}", 5, NULL },
  64.     { "[]{}(){}", "()(){}[]", 10, NULL },
  65.     { "1l!", "|||", 10, NULL },
  66.     { "\"``,;;_g%SSOOLIIlIC27p",
  67.       "''\".:i-9X$5o0ll11[[Z?P", 10, NULL },
  68.     { "''\".:i-9X$5o0ll11[[Z?P",
  69.       "\"``,;;_g%SSOOLIIlIC27p", 10, NULL },
  70.     /* Guessed errors, that might happen */
  71.     { "8B6G", "B8G6", 15, NULL },
  72.     /* Some common insertion errors */
  73.     { ".,'`", NULL, 10, NULL },
  74.     { NULL, NULL, 0, NULL }
  75. };
  76.  
  77. /* The many-to-many substitutions */
  78. struct RawSubst const substMultiples[] = {
  79.         { "''", "\"", 10, NULL },
  80.         { "``", "\"", 10, NULL },
  81.         { " ", "  ", 15, NULL },
  82.         { "NIA", "MA", 9, NULL },
  83.         { "riM", "NM", 9, NULL },
  84.         { "\n", " */\n", 15, NULL },
  85.     /* Tab-stop wonders */
  86.     { TAB_STRING" ", TAB_STRING"  ", 0, TabFilter },
  87.     { TAB_STRING" ", TAB_STRING"   ", 0, TabFilter },
  88.     { TAB_STRING" ", TAB_STRING"    ", 0, TabFilter },
  89.     { TAB_STRING" ", TAB_STRING"     ", 0, TabFilter },
  90.     { TAB_STRING" ", TAB_STRING"      ", 0, TabFilter },
  91.     { TAB_STRING" ", TAB_STRING"       ", 0, TabFilter },
  92.     { TAB_STRING" ", TAB_STRING"        ", 0, TabFilter },
  93.     { TAB_STRING" ", TAB_STRING"         ", 0, TabFilter },
  94.     { TAB_STRING" ", TAB_STRING"          ", 0, TabFilter },
  95.     { TAB_STRING" ", TAB_STRING"           ", 0, TabFilter },
  96.     { TAB_STRING" ", TAB_STRING"            ", 0, TabFilter },
  97.     { TAB_STRING" ", TAB_STRING"             ", 0, TabFilter },
  98.     { TAB_STRING" ", TAB_STRING"              ", 0, TabFilter },
  99.     { TAB_STRING" ", TAB_STRING"               ", 0, TabFilter },
  100.     { TAB_STRING" ", TAB_STRING"                ", 0, TabFilter },
  101.     { TAB_STRING" ", TAB_STRING"                 ", 0, TabFilter },
  102.     { TAB_STRING" ", TAB_STRING"                  ", 0, TabFilter },
  103.     { TAB_STRING" ", TAB_STRING"                   ", 0, TabFilter },
  104.     { TAB_STRING" ", TAB_STRING"                    ", 0, TabFilter },
  105. #if TAB_PAD_CHAR != ' '
  106. #error Fix those tab patterns!
  107. #endif
  108.     { NULL, NULL, 0, NULL }
  109. };
  110.